package com.loongtech.bi.advertisment.service.impl;

import com.loongtech.bi.action.PageHelper;
import com.loongtech.bi.advertisment.model.*;
import com.loongtech.bi.advertisment.service.AdvDayDataService;
import com.loongtech.bi.dao.CommonDao;
import com.loongtech.bi.entity.pay.EntityAdvNewUserLTV;
import com.loongtech.core.util.Time;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.lang.reflect.Method;
import java.util.*;

@Service("advDayDataService")
public class AdvDayDataServiceImpl implements AdvDayDataService {

    @Resource(name = "commonDao")
    private CommonDao commonDao;

    @Override
    public List<ActiveUrlTranData> getActiveTranDatas(String startday, String endday, String[] selectedAffiliation,
                                                      String[] selectedChannelName, String[] selectedAgent, String[] selectedPlatform, String[] selectedPaytype,
                                                      String[] selectedAdvPosition) throws Exception {

        StringBuilder sql = new StringBuilder();
        sql.append("select a.dateStr,a.url,a.advPosition,a.channelName,a.agent,a.clkEquipment,a.actEquipment, ");
        sql.append("a.newActive,a.newEquipment,a.newAccount,a.newPay,a.newPayUser,ifnull(b.totalpay,0) totalpay,d.num,round(d.num/a.newAccount,2) as tpr from ( ");
        sql.append("select ifnull(a.logdate,'')  as dateStr, ");
        sql.append("ifnull(a.url,'') url,ifnull(bi.advPosition,a.url) advPosition,ifnull(bi.channelName,a.url) channelName,ifnull(bi.agent,a.url) agent, ");
        sql.append("ifnull(tdclick,0) clkEquipment,ifnull(tdactivate,0) actEquipment, ");
        sql.append("ifnull(newactive,0) newActive , ifnull(newmac,0) newEquipment, ifnull(newuser,0) newAccount,round(ifnull(paymoney,0)/100) newPay, ifnull(payuser,0) newPayUser ");
        sql.append("from td_adv_active a  ");
        sql.append("left join bi_advconfig bi on a.url = bi.id  ");
        sql.append("where  a.logdate >=? and a.logdate <= ? ");
        if (selectedAffiliation != null && selectedAffiliation.length != 0) {
            sql.append("and affiliation in (" + getParams(selectedAffiliation) + ")");
        }
        if (selectedChannelName != null && selectedChannelName.length != 0) {
            sql.append("and channelName in (" + getParams(selectedChannelName) + ")");
        }
        if (selectedAgent != null && selectedAgent.length != 0) {
            sql.append("and agent in (" + getParams(selectedAgent) + ")");
        }
        if (selectedPlatform != null && selectedPlatform.length != 0) {
            sql.append("and platform in (" + getParams(selectedPlatform) + ")");
        }
        if (selectedPaytype != null && selectedPaytype.length != 0) {
            sql.append("and paytype in (" + getParams(selectedPaytype) + ")");
        }
        if (selectedAdvPosition != null && selectedAdvPosition.length != 0) {
            sql.append("and advPosition in (" + getParams(selectedAdvPosition) + ")");
        }
        sql.append(")a  left join(  ");
        sql.append("select ifnull(a.createdate,'')  as dateStr,   ");
        sql.append("ifnull(a.url,'') url,ifnull(bi.advPosition,a.url) advPosition,  ");
        sql.append("ifnull(bi.channelName,a.url) channelName,ifnull(bi.agent,a.url) agent,   ");
        sql.append("ifnull(sum(totalpay),0) totalpay    ");
        sql.append("from td_adv_totalpay a    ");
        sql.append("left join bi_advconfig bi on a.url = bi.id    ");
        sql.append("where a.createdate >= ? and a.createdate <= ?  ");
        if (selectedAffiliation != null && selectedAffiliation.length != 0) {
            sql.append("and affiliation in (" + getParams(selectedAffiliation) + ")");
        }
        if (selectedChannelName != null && selectedChannelName.length != 0) {
            sql.append("and channelName in (" + getParams(selectedChannelName) + ")");
        }
        if (selectedAgent != null && selectedAgent.length != 0) {
            sql.append("and agent in (" + getParams(selectedAgent) + ")");
        }
        if (selectedPlatform != null && selectedPlatform.length != 0) {
            sql.append("and platform in (" + getParams(selectedPlatform) + ")");
        }
        if (selectedPaytype != null && selectedPaytype.length != 0) {
            sql.append("and paytype in (" + getParams(selectedPaytype) + ")");
        }
        if (selectedAdvPosition != null && selectedAdvPosition.length != 0) {
            sql.append("and advPosition in (" + getParams(selectedAdvPosition) + ")");
        }
        sql.append("group by a.createdate,a.url,bi.channelName,bi.agent  ");
        sql.append(")b  ");
        sql.append("on a.dateStr = b.dateStr and a.url = b.url and a.advPosition = b.advPosition and a.channelName = b.channelName ");
        sql.append("and a.agent = b.agent  ");
        sql.append(" left join (select ifnull(a.createdate,'')  as dateStr, ifnull(a.url,'') as url,  ifnull(sum(num),0) num   from td_adv_totalpayuser a  left join bi_advconfig bi on a.url = bi.id ");
        sql.append("where a.createdate >=? and a.createdate <=?  ");
        if (selectedAffiliation != null && selectedAffiliation.length != 0) {
            sql.append("and bi.affiliation in (" + getParams(selectedAffiliation) + ")");
        }
        if (selectedChannelName != null && selectedChannelName.length != 0) {
            sql.append("and bi.channelName in (" + getParams(selectedChannelName) + ")");
        }
        if (selectedAgent != null && selectedAgent.length != 0) {
            sql.append("and bi.agent in (" + getParams(selectedAgent) + ")");
        }
        if (selectedPlatform != null && selectedPlatform.length != 0) {
            sql.append("and bi.platform in (" + getParams(selectedPlatform) + ")");
        }
        if (selectedPaytype != null && selectedPaytype.length != 0) {
            sql.append("and bi.paytype in (" + getParams(selectedPaytype) + ")");
        }
        if (selectedAdvPosition != null && selectedAdvPosition.length != 0) {
            sql.append("and bi.advPosition in (" + getParams(selectedAdvPosition) + ")");
        }
        sql.append(" group by a.createdate,a.url)d on a.dateStr = d.dateStr  and a.url=d.url ");
        sql.append("order by a.dateStr desc  , clkEquipment desc  ");
        return commonDao.queryObjList(sql.toString(), new Object[]{startday, endday, startday, endday, startday, endday},
                ActiveUrlTranData.class);
    }

    @Override
    public List<ActiveUrlTranData> getActiveTranDatasByChannel(String startday, String endday, String[] selectedAffiliation,
                                                               String[] selectedChannelName,String[] selectedAgent,
                                                               String[] selectedPlatform, String[] selectedPaytype,
                                                               String[] selectedAdvPosition) {

        StringBuilder sql = new StringBuilder();
        sql.append("select ifnull(a.logdate,'')  as dateStr, ");
        sql.append("ifnull(bi.channelName,a.url) channelName, ");
        sql.append("ifnull(sum(tdactivate),0) actEquipment, ");
        sql.append("ifnull(sum(newuser),0) newAccount, ifnull(sum(payuser),0) newPayUser ");
        sql.append("from td_adv_active a  ");
        sql.append("left join bi_advconfig bi on a.url = bi.id  ");
        sql.append("where  a.logdate >=? and a.logdate <= ? ");
        if (selectedAffiliation != null && selectedAffiliation.length != 0) {
            sql.append("and affiliation in (" + getParams(selectedAffiliation) + ")");
        }
        if (selectedAgent != null && selectedAgent.length != 0) {
            sql.append("and agent in (" + getParams(selectedAgent) + ")");
        }
        if (selectedChannelName != null && selectedChannelName.length != 0) {
            sql.append("and channelName in (" + getParams(selectedChannelName) + ")");
        }
        if (selectedPlatform != null && selectedPlatform.length != 0) {
            sql.append("and platform in (" + getParams(selectedPlatform) + ")");
        }
        if (selectedPaytype != null && selectedPaytype.length != 0) {
            sql.append("and paytype in (" + getParams(selectedPaytype) + ")");
        }
        if (selectedAdvPosition != null && selectedAdvPosition.length != 0) {
            sql.append("and advPosition in (" + getParams(selectedAdvPosition) + ")");
        }
        sql.append(" group by a.logdate, bi.channelName order by a.logdate desc, actEquipment desc  ");
        System.out.println("channel:" + sql);
        return commonDao.queryObjList(sql.toString(), new Object[]{startday, endday},
                ActiveUrlTranData.class);
    }

    @Override
    public List<ActiveUrlTranData> getActiveTranDatasByAgent(String startday, String endday, String[] selectedAffiliation, String[] selectedChannelName, String[] selectedAgent,  String[] selectedPlatform, String[] selectedPaytype, String[] selectedAdvPosition) {
        StringBuilder sql = new StringBuilder();
        sql.append("select ifnull(a.logdate,'')  as dateStr, ");
        sql.append("ifnull(bi.agent,a.url) agent, ");
        sql.append("ifnull(sum(tdactivate),0) actEquipment, ");
        sql.append("ifnull(sum(newuser),0) newAccount, ifnull(sum(payuser),0) newPayUser ");
        sql.append("from td_adv_active a  ");
        sql.append("left join bi_advconfig bi on a.url = bi.id  ");
        sql.append("where  a.logdate >=? and a.logdate <= ? ");
        if (selectedAffiliation != null && selectedAffiliation.length != 0) {
            sql.append("and affiliation in (" + getParams(selectedAffiliation) + ")");
        }
        if (selectedAgent != null && selectedAgent.length != 0) {
            sql.append("and agent in (" + getParams(selectedAgent) + ")");
        }
        if (selectedChannelName != null && selectedChannelName.length != 0) {
            sql.append("and channelName in (" + getParams(selectedChannelName) + ")");
        }
        if (selectedPlatform != null && selectedPlatform.length != 0) {
            sql.append("and platform in (" + getParams(selectedPlatform) + ")");
        }
        if (selectedPaytype != null && selectedPaytype.length != 0) {
            sql.append("and paytype in (" + getParams(selectedPaytype) + ")");
        }
        if (selectedAdvPosition != null && selectedAdvPosition.length != 0) {
            sql.append("and advPosition in (" + getParams(selectedAdvPosition) + ")");
        }
        sql.append(" group by a.logdate,bi.agent");
        sql.append(" order by a.logdate desc, actEquipment desc  ");
        System.out.println("agent:" + sql);
        return commonDao.queryObjList(sql.toString(), new Object[]{startday, endday},
                ActiveUrlTranData.class);
    }

    @Override
    public List<NewRemainData> getNewRemainDatas(String startday, String endday, String[] selectedAffiliation,
                                                 String[] selectedChannelName, String[] selectedAgent, String[] selectedPlatform, String[] selectedPaytype,
                                                 String[] selectedAdvPosition) throws Exception {
        System.out.println("进入方法:" + Time.getDateAndHourStr(new Date()));
        Map<String, NewRemainData> result = new LinkedHashMap<>();
        StringBuilder sql2 = new StringBuilder();
        sql2.append("select ifnull(createdate,'') tcreatedate, t.logdate logdate, t.url url, ifnull(t.remainnum, 0) tremainnum, bi.advPosition , ifnull(bi.channelName,t.url) channelName,ifnull(bi.agent,t.url) agent");
        sql2.append(" from td_adv_newremain t ");
        sql2.append(" left join bi_advconfig bi on t.url = bi.id ");
        sql2.append("left join td_adv_active act on t.url = act.url and t.createdate = act.logdate ");
        sql2.append("where t.createdate >= ? and t.createdate <=? and act.newuser > 4 ");
        if (selectedAffiliation != null && selectedAffiliation.length != 0) {
            sql2.append("and affiliation in (" + getParams(selectedAffiliation) + ")");
        }
        if (selectedChannelName != null && selectedChannelName.length != 0) {
            sql2.append("and channelName in (" + getParams(selectedChannelName) + ")");
        }
        if (selectedAgent != null && selectedAgent.length != 0) {
            sql2.append("and agent in (" + getParams(selectedAgent) + ")");
        }
        if (selectedPlatform != null && selectedPlatform.length != 0) {
            sql2.append("and platform in (" + getParams(selectedPlatform) + ")");
        }
        if (selectedPaytype != null && selectedPaytype.length != 0) {
            sql2.append("and paytype in (" + getParams(selectedPaytype) + ")");
        }
        if (selectedAdvPosition != null && selectedAdvPosition.length != 0) {
            sql2.append("and advPosition in (" + getParams(selectedAdvPosition) + ") ");
        }
        sql2.append("order by t.url, createdate, logdate");
        System.out.println("进入sql:" + Time.getDateAndHourStr(new Date()));
        List<NewRemainData2> temp2 = commonDao.queryObjList(sql2.toString(), new Object[]{startday, endday}, NewRemainData2.class);
        System.out.println("sql执行完毕:" + Time.getDateAndHourStr(new Date()));
        for (NewRemainData2 data : temp2) {
            if (data.isNew()) {
                NewRemainData value = new NewRemainData();
                value.setAdvPosition(data.getAdvPosition());
                value.setAgent(data.getAgent());
                value.setChannelName(data.getChannelName());
                value.setDateStr(data.getTcreatedate());
                value.setUrl(data.getUrl());
                value.setNewAccount(data.getTremainnum());
                result.put(data.getKey(), value);
            } else {
                NewRemainData tmp = result.get(data.getKey());
                if (tmp != null) {
                    int interval = data.getInterval() + 1;
                    String methodStr = "setRemain" + interval;
                    String remainValue = PageHelper.floatKeep4Number(data.getTremainnum() * 1.0 / tmp.getNewAccount()).toString();
                    Method mRes = tmp.getClass().getMethod(methodStr, String.class);
                    mRes.invoke(tmp, remainValue);
                }
            }
        }
        System.out.println("方法完成:" + Time.getDateAndHourStr(new Date()));
        return new ArrayList<>(result.values());
    }

    private String getRemain(int newUser, int remain) {
        return newUser == 0 ? "0" : (remain * 1.0 / newUser) + "";
    }

    @Override
    public List<TotalPayData> getTotalPayDatas(String startday, String endday, String[] selectedAffiliation,
                                               String[] selectedChannelName, String[] selectedAgent, String[] selectedPlatform, String[] selectedPaytype,
                                               String[] selectedAdvPosition) throws Exception {
        Map<String, TotalPayData> result = new LinkedHashMap<>();
        StringBuilder sql2 = new StringBuilder();
        sql2.append("select ifnull(createdate,'') tcreatedate, t.logdate logdate, t.url url, ifnull(t.totalpay, 0) totalpay, bi.advPosition , ifnull(bi.channelName,t.url) channelName,ifnull(bi.agent,t.url) agent, ifnull(act.newuser,0)newAccount");
        sql2.append(" from td_adv_totalpay t ");
        sql2.append(" left join bi_advconfig bi on t.url = bi.id ");
        sql2.append("left join td_adv_active act on t.url = act.url and t.createdate = act.logdate ");
        sql2.append("where t.createdate >= ? and t.createdate <=? ");
        if (selectedAffiliation != null && selectedAffiliation.length != 0) {
            sql2.append("and affiliation in (" + getParams(selectedAffiliation) + ")");
        }
        if (selectedChannelName != null && selectedChannelName.length != 0) {
            sql2.append("and channelName in (" + getParams(selectedChannelName) + ")");
        }
        if (selectedAgent != null && selectedAgent.length != 0) {
            sql2.append("and agent in (" + getParams(selectedAgent) + ")");
        }
        if (selectedPlatform != null && selectedPlatform.length != 0) {
            sql2.append("and platform in (" + getParams(selectedPlatform) + ")");
        }
        if (selectedPaytype != null && selectedPaytype.length != 0) {
            sql2.append("and paytype in (" + getParams(selectedPaytype) + ")");
        }
        if (selectedAdvPosition != null && selectedAdvPosition.length != 0) {
            sql2.append("and advPosition in (" + getParams(selectedAdvPosition) + ") ");
        }
        sql2.append("order by t.url, createdate, logdate");
        System.out.println("进入totalsql:" + Time.getDateAndHourStr(new Date()));
        List<TotalPayData2> temp2 = commonDao.queryObjList(sql2.toString(), new Object[]{startday, endday}, TotalPayData2.class);
        long nowVale = 0L;
        for (TotalPayData2 data : temp2) {
            if (data.isNew()) {
                TotalPayData value = new TotalPayData(data.getTcreatedate());
                value.setAdvPosition(data.getAdvPosition());
                value.setAgent(data.getAgent());
                value.setChannelName(data.getChannelName());
                value.setUrl(data.getUrl());
                value.setNewAccount(data.getNewAccount());
                nowVale = data.getTotalpay();
                value.setIncome1(String.valueOf(nowVale));
                result.put(data.getKey(), value);
            } else {
                TotalPayData tmp = result.get(data.getKey());
                if (tmp != null) {
                    nowVale += data.getTotalpay();
                    int interval = data.getInterval() + 1;
                    if (interval > 90) {
                        continue;
                    }
                    String methodStr = "setIncome" + interval;
                    Method mRes = tmp.getClass().getMethod(methodStr, String.class);
                    mRes.invoke(tmp, String.valueOf(nowVale));
                }
            }
        }
        return new ArrayList<>(result.values());
    }

    private String getSelRemainParams(int days, String name, String paramName) {
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i < days; i++) {
            sb.append(", if(date_add(STR_TO_DATE(createdate,'%Y-%m-%d'),interval "
                    + i
                    + " day)>=curdate(),'-',sum(if(t.logdate=DATE_FORMAT(date_add(STR_TO_DATE(createdate,'%Y-%m-%d'),interval "
                    + i
                    + " day),'%Y-%m-%d'), round("
                    + name
                    + "/(select newuser from td_adv_active where logdate = DATE_FORMAT(date_add(STR_TO_DATE(createdate,'%Y-%m-%d'),interval 0 day),'%Y-%m-%d') and url = t.url),4),''))+'') "
                    + paramName + (i + 1) + " ");
        }
        return sb.toString();
    }

    private String getSelPayParams(int days, String name, String paramName) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < days; i++) {
            sb.append(", if(date_add(STR_TO_DATE(createdate,'%Y-%m-%d'),interval "
                    + i
                    + " day)>=curdate(),-1,sum(if(t.logdate=DATE_FORMAT(date_add(STR_TO_DATE(createdate,'%Y-%m-%d'),interval "
                    + i + " day),'%Y-%m-%d'), " + name + ",0))) " + paramName + (i + 1) + " ");
        }
        return sb.toString();
    }

    private String getParams(String[] param) {
        StringBuilder s = new StringBuilder();
        for (String str : param) {
            s.append("'" + str + "',");
        }
        return s.substring(0, s.length() - 1);
    }

    @Override
    public List<EntityAdvNewUserLTV> getLTVPay(String startday, String endday, String[] selectedAffiliation, String[] selectedChannelName,
                                               String[] selectedAgent, String[] selectedPlatform,
                                               String[] selectedPaytype, String[] selectedAdvPosition) {
        StringBuilder sql = new StringBuilder();
        sql.append("select ifnull(startday,'') startday, ifnull(endday,'') endday, t.url url, ifnull(sum(t.cashadd), 0) cashadd, ifnull(bi.channelName,t.url) channelName,ifnull(bi.agent,t.url) agent from td_adv_newuserltvbyurl t " +
                "left join bi_advconfig bi on t.url = bi.id  where t.startday>=? and t.startday<= ? and t.endday<=? ");
        if (selectedAffiliation != null && selectedAffiliation.length != 0) {
            sql.append(" and affiliation in (" + getParams(selectedAffiliation) + ")");
        }
        if (selectedAgent != null && selectedAgent.length != 0) {
            sql.append(" and agent in (" + getParams(selectedAgent) + ")");
        }
        if (selectedChannelName != null && selectedChannelName.length != 0) {
            sql.append(" and channelName in (" + getParams(selectedChannelName) + ")");
        }
        if (selectedPlatform != null && selectedPlatform.length != 0) {
            sql.append(" and platform in (" + getParams(selectedPlatform) + ")");
        }
        if (selectedPaytype != null && selectedPaytype.length != 0) {
            sql.append(" and paytype in (" + getParams(selectedPaytype) + ")");
        }
        if (selectedAdvPosition != null && selectedAdvPosition.length != 0) {
            sql.append(" and advPosition in (" + getParams(selectedAdvPosition) + ")");
        }
        sql.append(" group by t.url,bi.channelName,bi.agent,t.startday,t.endday order by t.startday");
        System.out.println("qqqq" + sql);
        return commonDao.queryObjList(sql.toString(), new Object[]{startday, endday, Time.formatTime(Time.formatDateStr(endday, Time.TIMEPATTERN_SIMPLE) + 179 * Time.DAY, Time.TIMEPATTERN_SIMPLE)}, EntityAdvNewUserLTV.class);
    }

    @Override
    public List<EntityAdvNewUserLTV> getLTVPayByAgent(String startday, String endday, String[] selectedAffiliation, String[] selectedChannelName,
                                                      String[] selectedAgent, String[] selectedPlatform,
                                                      String[] selectedPaytype, String[] selectedAdvPosition) {
        StringBuilder sql = new StringBuilder();
        sql.append("select ifnull(startday,'') startday, ifnull(endday,'') endday,ifnull(bi.agent,t.url) agent, ifnull(sum(t.cashadd), 0) cashadd from td_adv_newuserltvbyurl t " +
                "left join bi_advconfig bi on t.url = bi.id  where t.startday>=? and t.startday<= ? and t.endday<=? ");
        if (selectedAffiliation != null && selectedAffiliation.length != 0) {
            sql.append("and affiliation in (" + getParams(selectedAffiliation) + ")");
        }
        if (selectedAgent != null && selectedAgent.length != 0) {
            sql.append(" and agent in (" + getParams(selectedAgent) + ")");
        }
        if (selectedChannelName != null && selectedChannelName.length != 0) {
            sql.append(" and channelName in (" + getParams(selectedChannelName) + ")");
        }
        if (selectedPlatform != null && selectedPlatform.length != 0) {
            sql.append(" and platform in (" + getParams(selectedPlatform) + ")");
        }
        if (selectedPaytype != null && selectedPaytype.length != 0) {
            sql.append(" and paytype in (" + getParams(selectedPaytype) + ")");
        }
        if (selectedAdvPosition != null && selectedAdvPosition.length != 0) {
            sql.append(" and advPosition in (" + getParams(selectedAdvPosition) + ")");
        }
        sql.append(" group by bi.agent,t.startday,t.endday order by t.startday");
        System.out.println("agent for ltv is: " + sql);
        return commonDao.queryObjList(sql.toString(), new Object[]{startday, endday, Time.formatTime(Time.formatDateStr(endday, Time.TIMEPATTERN_SIMPLE) + 179 * Time.DAY, Time.TIMEPATTERN_SIMPLE)}, EntityAdvNewUserLTV.class);
    }

    @Override
        public List<EntityAdvNewUserLTV> getLTVPayByChannel(String startday, String endday, String[] selectedAffiliation, String[] selectedChannelName,
                                                        String[] selectedAgent, String[] selectedPlatform,
                                                        String[] selectedPaytype, String[] selectedAdvPosition) {
        StringBuilder sql = new StringBuilder();
        sql.append("select ifnull(startday,'') startday, ifnull(endday,'') endday, ifnull(bi.channelName,t.url) channelName, ifnull(sum(t.cashadd), 0) cashadd from td_adv_newuserltvbyurl t " +
                "left join bi_advconfig bi on t.url = bi.id  where t.startday>=? and t.startday<= ? and t.endday<=? ");
        if (selectedAffiliation != null && selectedAffiliation.length != 0) {
            sql.append("and affiliation in (" + getParams(selectedAffiliation) + ")");
        }
        if (selectedAgent != null && selectedAgent.length != 0) {
            sql.append(" and agent in (" + getParams(selectedAgent) + ")");
        }
        if (selectedChannelName != null && selectedChannelName.length != 0) {
            sql.append(" and channelName in (" + getParams(selectedChannelName) + ")");
        }
        if (selectedPlatform != null && selectedPlatform.length != 0) {
            sql.append(" and platform in (" + getParams(selectedPlatform) + ")");
        }
        if (selectedPaytype != null && selectedPaytype.length != 0) {
            sql.append(" and paytype in (" + getParams(selectedPaytype) + ")");
        }
        if (selectedAdvPosition != null && selectedAdvPosition.length != 0) {
            sql.append(" and advPosition in (" + getParams(selectedAdvPosition) + ")");
        }
        sql.append(" group by bi.channelName,t.startday,t.endday order by t.startday");
        System.out.println("channel for ltv is: " + sql);
        return commonDao.queryObjList(sql.toString(), new Object[]{startday, endday, Time.formatTime(Time.formatDateStr(endday, Time.TIMEPATTERN_SIMPLE) + 179 * Time.DAY, Time.TIMEPATTERN_SIMPLE)}, EntityAdvNewUserLTV.class);
    }
}
